//
//  XYBaseNavViewController.swift
//  01.XinLangWB
//
//  Created by 肖玉东 on 16/4/13.
//  Copyright © 2016年 苏小样. All rights reserved.
//

import UIKit

class XYBaseNavViewController: UINavigationController,UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        //设置导航栏的背景颜色
//        navigationBar.setBackgroundImage(UIImage(named: "tabbar_background"), forBarMetrics: .Default)
        //设置手势
        self.interactivePopGestureRecognizer?.delegate = self

        // Do any additional setup after loading the view.
    }
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        //print(childViewControllers.count)
        if childViewControllers.count > 0{
            var backTitle = "返回"
            if childViewControllers.count == 1{
                backTitle = childViewControllers.first?.title ?? ""
            }
            
        viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: backTitle, target: self, action: "back")
            //隐藏底部的标签栏
            viewController.hidesBottomBarWhenPushed = true
            //设置颜色  页面跳转的时候会有颜色切换 导致卡顿
            viewController.view.backgroundColor = UIColor.whiteColor()
        }
        
        super.pushViewController(viewController, animated: true)
        //print(childViewControllers.count)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    @objc private func back(){
        print("back")
        self.popViewControllerAnimated(true)
    }
    //MARK:手势将要结束的协议方法 解决在首页的时候还可以一直滑动导致不能点击
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        print("哈哈")
        return childViewControllers.count != 1
    }
}
